<?php

$headers = getallheaders();
if ($headers['x-requested-with'] == 'XMLHttpRequest') {
    if ($_REQUEST['get'] == 'imgsrc') {
        header('Cache-Control: no-cache, must-revalidate');
        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
        header('Content-type: application/json');
        $filelist = glob('img/*sprites.png');
        foreach ($filelist as $k => &$filename) {
            $dataname = str_replace(array('img/', '-sprites.png'), array('', ''), $filename);
        	$jsonFilename = str_replace(array('img','.png'), array('data','.json'), $filename);

            $handle = fopen($filename, "r");
            $image_contents = fread($handle, filesize($filename));
            fclose($handle);
/*
            $json_contents = parse_ini_file($jsonFilename,true);
            print_r($json_contents);

            $filelist[$dataname] = array(
                'image' => 'data:image/png;base64,' . base64_encode($image_contents),
                'data' => $json_contents
            );
*/

			$filelist[$dataname] = 'data:image/png;base64,' . base64_encode($image_contents);
			unset($filelist[$k]);

        }
echo json_encode($filelist);
    }
}
